<template>
  <svg :class="svgClass" aria-hidden="true">
    <title v-if="title">{{ title }}</title>
    <use :xlink:href="iconName" />
  </svg>
</template>

<script lang="ts" setup>
import { computed } from "@vue/runtime-core";

interface Props {
  iconClass: string;
  popperClass?: string;
  title?: string;
}
const props = withDefaults(defineProps<Props>(), {
  popperClass: "",
  title: "",
});
/**
 * icon图标的对应名称(位置)
 */
const iconName = computed(() => `#icon-${props.iconClass}`);
/**
 * icon图标的对应的class类名(用作css样式)
 */
const svgClass = computed(() =>
  props.popperClass ? "svg-icon " + props.popperClass : "svg-icon"
);
</script>

<style lang="scss" scoped>
.svg-icon {
  @include setWidHei(1em, 1em);
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
</style>
